﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ClassLibrary.Data;
using System.Data;
using ClassLibrary.Entity;

namespace ClassLibrary.DAO
{
    public class TblDSLKDAO
    {
         private DBService _db = null;

         public TblDSLKDAO(String connectionString)
        {
            _db = new DBService(connectionString);
        }

        public DataTable InsUpDSLK(TblDSLK dslk, int mode)
        {
            DataTable flag = null;
            try
            {
                flag = _db.ExeSP_DataTable("sp_TblDanhSachLienKet_InsUp",
                    new string[] { "@ID", "@Name", "@NavigateUrl", "@Mode" },
                    new object[] { dslk.ID, dslk.Name, dslk.NavigateUrl, mode }, CommandType.StoredProcedure);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return flag;
        }

        public DataTable GetDSLK()
        {
            DataTable dslk = null;
            try
            {
                dslk = _db.ExeSP_DataTable("select * from TblDanhSachLienKet", false, CommandType.Text);

            }
            catch (Exception ex)
            {
                throw ex;
            }
            return dslk;
        }

        public TblDSLK GetDSLKByID(int ID)
        {
            TblDSLK dslk = new TblDSLK();

            try
            {
                DataTable Menu = null;
                Menu = _db.ExeSP_DataTable("select * from TblDanhSachLienKet where ID = @ID",
                    new string[] { "@ID" },
                    new object[] { ID }
                        , CommandType.Text);
                foreach (DataRow dr in Menu.Rows)
                {
                    dslk.ID = ID;
                    dslk.Name = dr["Name"].ToString();
                    dslk.NavigateUrl = dr["NavigateUrl"].ToString();

                }

            }
            catch (Exception ex)
            {
                throw ex;
            }
            return dslk;
        }

        public bool DeleteDSLK(TblDSLK dslk)
        {
            bool flag = false;
            try
            {
                _db.ExeSP_NonQuery("delete TblDanhSachLienKet where ID = @ID",
                    new string[] { "@ID" },
                    new object[] { dslk.ID },
                    CommandType.Text);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return flag;
        }
    }
}
